package com.syyo.gulimall.search.controller;

import com.syyo.common.domain.ResultVo;
import com.syyo.common.to.es.SkuEsModel;
import com.syyo.common.utils.ResultUtils;
import com.syyo.gulimall.search.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @author: wang
 * @date: 2021/3/24 15:40
 * @Description:
 */
@RestController
@RequestMapping("/search/save")
public class ElasticController {


    @Autowired
    private ProductService productService;

    /**
     * 上架商品
     *
     * @param list
     * @return
     */
    @PostMapping("/product")
    public ResultVo productStatusUp(@RequestBody List<SkuEsModel> list) {

        boolean b = false;
        try {
            b = productService.add(list);
        } catch (IOException e) {
            e.printStackTrace();
            return ResultUtils.error("远程调用失败");
        }

        if (!b) {
            return ResultUtils.ok(1);
        } else {
            return ResultUtils.error("远程调用失败");
        }
    }
}
